{include file="header.htm" /}
<script type="text/javascript" src="__PUBLIC__/plugins/Echarts/echarts.min.js"></script>
<link href="__WEAPP_TEMPLATE__/skin/css/main_new.css?v={$weappInfo.version|default='v1.0.0'}" rel="stylesheet" type="text/css">
<body class="bodystyle">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page min-hg-c-50">
    <div class="flexigrid flexigrid-xin">
        <div class="header-bar">
            <div class="more">
                <div class="search">
                    <div class="content p10">
                        <div class="ey-form-item">
                            <label class="users-form-item-label">批量设置：</label>
                            <!-- <div class="users-form-item-content">
                                <div class="users-select">
                                    <div tabindex="0" class="users-select-selection">
                                        <label><input type="checkbox" id="batchSpecJoin" title="参与积分商城">&nbsp;参与积分商城</label>
                                    </div>
                                </div>
                            </div> -->
                        </div>

                        <div class="ey-form-item">
                            <div class="users-form-item-content">
                                <div class="users-select">
                                    <div tabindex="0" class="users-select-selection">
                                        <div class="sDiv2">
                                            <input type="text" size="50" id="batchSpecPoints" class="qsbox" placeholder="0" style="vertical-align: unset" onpaste="this.value=this.value.replace(/[^\d]/g, '');" onkeyup="this.value=this.value.replace(/[^\d]/g, '');">&nbsp;积分&nbsp;
                                        </div>
                                        <span>+</span>
                                        <div class="sDiv2">
                                            <input type="text" size="50" id="batchSpecPrice" class="qsbox" placeholder="0" style="vertical-align: unset" onpaste="this.value=this.value.replace(/[^\d.]/g, '');" onkeyup="this.value=this.value.replace(/[^\d.]/g, '');">&nbsp;元&nbsp;
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="ey-form-item">
                            <div class="users-form-item-content">
                                <div class="users-select">
                                    <div tabindex="0" class="users-select-selection">
                                        <div class="sDiv2">
                                            <input type="text" size="50" id="batchSpecStock" class="qsbox" placeholder="0" style="vertical-align: unset" onpaste="this.value=this.value.replace(/[^\d]/g, '');" onkeyup="this.value=this.value.replace(/[^\d]/g, '');">&nbsp;件&nbsp;
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="ey-form-item" style="margin-left: 20px;">
                            <div class="users-form-item-content">
                                <span class="bt-xin" onclick="batchSetUse();">应用</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="flexigrid">
        <div class="bDiv mt15" style="height: auto;">
            <form id="goodsSpecForm">
                <input type="hidden" id="aid" name="aid" value="{$aid}">
                <input type="hidden" id="goods_id" name="goods_id" value="{$goods_id}">
                <div id="goodsSpecCombi">{$goodsSpecCombi}</div>
            </form>
        </div>
    </div>

    <div class="bot3">
        <a href="javascript:void(0);" onclick="submitGoodsSpec();" class="ncap-btn-big ncap-btn-green"><span>确认</span></a>
        <a class="ncap-btn-big ncap-btn-no" href="javascript:void(0);" onclick="parent.closeSelectGoods(false);" title="关闭">关闭</a>
    </div>
</div>
  
<script type="text/javascript">
    $(function () {
        // 合并商品规格单元格
        mergeGoodsSpecCells();
    });

    // 合并商品规格单元格
    function mergeGoodsSpecCells() {
        var tab = document.getElementById("goodsSpecTable");
        var maxCol = 2, val, count, start; 
        if (tab != null) {
            for (var col = maxCol - 1; col >= 0; col--) {
                count = 1;
                val = "";
                for (var i = 0; i < tab.rows.length; i++) {
                    if (val == tab.rows[i].cells[col].innerHTML) {
                        count++;
                    } else {
                        if (count > 1) {
                            start = i - count;
                            tab.rows[start].cells[col].rowSpan = count;
                            for (var j = start + 1; j < i; j++) {
                                tab.rows[j].cells[col].style.display = "none";
                            }
                            count = 1;
                        }
                        val = tab.rows[i].cells[col].innerHTML;
                    }
                }
                if (count > 1) {
                    start = i - count;
                    tab.rows[start].cells[col].rowSpan = count;
                    for (var j = start + 1; j < i; j++) {
                        tab.rows[j].cells[col].style.display = "none";
                    }
                }
            }
        }
    }

    // 批量设置
    function batchSetUse() {
        var batchSpecPoints = $('#batchSpecPoints').val() ? $('#batchSpecPoints').val() : 0;
        if (0 >= parseInt(batchSpecPoints)) {
            layer.alert('请输入购买所需积分', {title: false, closeBtn: false}, function() {
                layer.closeAll();
                $('#batchSpecPoints').focus();
            });
            return false;
        }
        var batchSpecStock = $('#batchSpecStock').val() ? $('#batchSpecStock').val() : 0;
        if (0 >= parseInt(batchSpecStock)) {
            layer.alert('请输入商品库存', {title: false, closeBtn: false}, function() {
                layer.closeAll();
                $('#batchSpecStock').focus();
            });
            return false;
        }
        // 批量设置商品库存
        $('.specStock').val(parseInt(batchSpecStock));
        // 批量设置商品积分
        $('.specPoints').val(parseInt(batchSpecPoints));
        // 批量参与积分商城
        // $('.specJoin').attr('checked', false);
        // if ($('#batchSpecJoin').is(':checked')) $('.specJoin').attr('checked', true);
        // 批量设置商品价格
        var batchSpecPrice = $('#batchSpecPrice').val() ? $('#batchSpecPrice').val() : 0;
        if (0 <= parseFloat(batchSpecPrice)) $('.specPrice').val(parseFloat(batchSpecPrice));
    }

    // 提交积分商品入库
    function submitGoodsSpec() {
        layer_loading('正在处理');
        $.ajax({
            url : "{:weapp_url('PointsShop/PointsShop/setGoodsSpec', ['_ajax'=>1])}",
            data: $('#goodsSpecForm').serialize(),
            type: 'post',
            dataType: 'json',
            success: function(res) {
                layer.closeAll();
                if (1 === parseInt(res.code)) {
                    var goodsID = $('#goods_id').val();
                    if (0 === parseInt(res.data.count)) {
                        parent.$('#notSet_' + goodsID).show();
                        parent.$('#hasSet_' + goodsID).hide();
                        parent.$('#goodsSpecSet_' + goodsID).val(0);
                    } else {
                        parent.$('#notSet_' + goodsID).hide();
                        parent.$('#hasSet_' + goodsID).show();
                        parent.$('#goodsSpecSet_' + goodsID).val(1);
                    }
                    layer.msg(res.msg, {time: 1000}, function() {
                        parent.layer.closeAll();
                    });
                } else {
                    layer.alert(res.msg, {icon: 0, title: false, closeBtn: false});
                }
            }
        });
    }


</script>
{include file="footer.htm" /}
